home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Voyeur 1.1.1 / Voyeur ƒ / v code ƒ / v files.c < prev    next >
Text File  |  1994-02-25  |  3KB  |  101 lines

  1. /**********************************************************************\
  2.  
  3. File:        v files.c
  4.  
  5. Purpose:    This module handles getting files (through the standard
  6.             file dialog).
  7.  
  8.  
  9. Voyeur -- a no-frills file viewer
  10. Copyright ©1993-4, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "Script.h"
  30. #include "v files.h"
  31. #include "msg graphics.h"
  32. #include "msg environment.h"
  33.  
  34. Boolean GetSourceFile(FSSpec *editFile)
  35. {
  36.     Point                where;
  37.     OSErr                isHuman;
  38.     StandardFileReply    reply;
  39.     SFReply                oldReply;
  40.     unsigned int        count;
  41.     FInfo                fndrInfo;
  42.     long                procID;
  43.     int                    i;
  44.     
  45.     isHuman=FALSE;
  46.     if (gStandardFile58)
  47.         StandardGetFile(0L, -1, 0L, &reply);
  48.     else
  49.     {
  50.         where.h = (gMainScreenBounds.right - 348)/2;
  51.         where.v = (gMainScreenBounds.bottom - 200)/3;
  52.         SFGetFile(where, "\p", 0L, -1, 0L, 0L, &oldReply);
  53.         
  54.         reply.sfGood = oldReply.good;
  55.         if (reply.sfGood)
  56.         {
  57.             reply.sfType = oldReply.fType;
  58.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  59.                                 &reply.sfFile.parID, &procID);
  60.             if (isHuman!=noErr)
  61.             {
  62.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  63.                 reply.sfFile.parID = 0;
  64.             }
  65.             count=oldReply.fName[0];
  66.             for (i=0; i<=count; i++)
  67.                 reply.sfFile.name[i]=oldReply.fName[i];
  68.             
  69.             reply.sfScript=smSystemScript;
  70.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  71.                                 reply.sfFile.name, &fndrInfo);
  72.             reply.sfFlags=(isHuman==noErr) ? fndrInfo.fdFlags : 0;
  73.             
  74.             reply.sfIsFolder=FALSE;
  75.             reply.sfIsVolume=FALSE;
  76.         }
  77.     }
  78.  
  79.     if ((reply.sfGood) && (!isHuman))
  80.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  81.                             editFile);
  82.         
  83.     return ((reply.sfGood) && (!isHuman));
  84. }
  85.  
  86. pascal OSErr MyMakeFSSpec(short vRefNum, long parID, ConstStr255Param fileName,
  87.     FSSpecPtr myFSS)
  88. {
  89.     int            i;
  90.     
  91.     if (gHasFSSpecs)
  92.         FSMakeFSSpec(vRefNum, parID, fileName, myFSS);
  93.     else
  94.     {
  95.         myFSS->vRefNum=vRefNum;
  96.         myFSS->parID=parID;
  97.         for (i=fileName[0]; i>=0; i--)
  98.             myFSS->name[i]=fileName[i];
  99.     }
  100. }
  101.